package cn.tedu.egmvc2.controller;

import cn.tedu.egmvc2.mapper.EmpMapper;
import cn.tedu.egmvc2.pojo.dto.EmpDTO;
import cn.tedu.egmvc2.pojo.entity.Emp;
import cn.tedu.egmvc2.pojo.vo.EmpVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emp/")
public class EmpController {

    @Autowired
    private EmpMapper empMapper;
    @PostMapping("insert")
    public String insertEmp(EmpDTO empDTO){
        Emp emp = new Emp();
        BeanUtils.copyProperties(empDTO,emp);
       empMapper.insertEmp(emp);
       return "添加成功";
    }

    @GetMapping("select")
    public List<EmpVO> selectEmp(){
        return empMapper.selectEmp();
    }

    @PostMapping("update")
    public String updateEmp(Emp emp){
        empMapper.updateEmp(emp);
        return "修改成功";
    }
    @GetMapping("delete/{id}")
    public String deleteEmp(@PathVariable int id){
        empMapper.deleteEmp(id);
        return "删除成功";
    }
}
